package test;

import test.entity.Person;

/**
 * 局部变量表GC和槽位复用
 * 
 * @author yuanZhi
 * @since 2021/6/22 14:49
 */
public class LocalValueGc {

	public static void main(String[] args) {
		LocalValueGc localValueGC = new LocalValueGc();
		localValueGC.Gc1();
		localValueGC.Gc2();
		localValueGC.Gc3();
		localValueGC.Gc4();
		localValueGC.Gc5();

		localValueGC.get();
		localValueGC.get1();
	}

	public void Gc1() {
		int[] a = { 1, 2, 3 }; // 存在着引用
		System.gc();
	}

	public void Gc2() {
		int[] a = { 1, 2, 3 };
		a = null; // 失去了引用
		System.gc();
	}

	public void Gc3() {
		{
			int[] a = { 1, 2, 3 };
			System.out.println(a);
		}
		System.gc();
	}

	// 槽位slot复用
	public void Gc4() {
		{
			int[] a = { 1, 2, 3 };
			System.out.println(a);
		}
		int b = 100;
		System.gc();
	}

	public void Gc5() {
		Person person = new Person();
		Gc1();
		System.gc();
	}

	public void get() {
		String a = "a";
		System.out.println(a);
		String b = "b";
	}

	public void get1() {
		{
			String a = "a";
			System.out.println(a);
		}
		String b = "b";
	}
}